"""
@Author  : 康帅
@Time    : 2021/3/24 13:50
@Function: 构建模式：玩具房子搭建
"""
from abc import ABCMeta, abstractmethod


class Toy(metaclass=ABCMeta):
    """ 玩具 """

    def __init__(self, name):
        self._name = name
        self._components = []

    def get_name(self):
        return self._name

    def add_component(self, component, count=1, unit="个"):
        self._components.append([component, count, unit])
        print("%s 增加了 %d %s%s" % (self._name, count, unit, component))

    @abstractmethod
    def feature(self):
        pass


class Car(Toy):
    """ 小车 """

    def feature(self):
        print(f"我是{self._name},可以快速奔跑")


class Manor(Toy):
    """ 庄园 """

    def feature(self):
        print(f"我是{self._name},可以观赏也可以游玩")


class ToyBuild:
    """ 玩具构建 """

    def build_car(self):
        car = Car("迷你小车")
        print(f"正在构建{car.get_name()}")
        car.add_component("轮子", 4)
        car.add_component("车身", 1)
        car.add_component("发动机", 1)
        car.add_component("方向盘")
        return car

    def build_manor(self):
        manor = Manor("涛涛小庄园")
        print(f"正在构建{manor.get_name()}")
        manor.add_component("客厅", 1, "间")
        manor.add_component("卧室", 2, "间")
        manor.add_component("书房", 1, "间")
        manor.add_component("厨房", 1, "间")
        manor.add_component("花园", 1)
        manor.add_component("围墙", 1, "堵")
        return manor


if __name__ == '__main__':
    build = ToyBuild()
    car = build.build_car()
    car.feature()
    print()

    manor = build.build_manor()
    manor.feature()
